﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using Tradex.Market;

namespace Tradex.Tests.Market {

    [TestClass]
    public class InstrumentKeyTests {

        [TestMethod]
        public void Constructor_Value () {
            const string market = "MARKET";
            const string instrument = "INSTRUMENT";
            InstrumentKey key = new InstrumentKey(market, instrument);
            Assert.AreEqual(market, key.Market);
            Assert.AreEqual(instrument, key.Instrument);
        }

        [TestMethod]
        public new void ToString () {
            const string market = "MARKET";
            const string instrument = "INSTRUMENT";
            InstrumentKey key = new InstrumentKey(market, instrument);
            Assert.AreEqual(String.Format("{0}/{1}", market, instrument), key.ToString());
        }

        [TestMethod]
        public void Equals_True () {
            const string market = "MARKET";
            const string instrument = "INSTRUMENT";
            InstrumentKey key = new InstrumentKey(market, instrument);
            Assert.IsTrue(key.Equals(key));
        }

        [TestMethod]
        public void Equals_False() {
            const string market = "MARKET";
            const string market2 = "MARKET2";
            const string instrument1 = "INSTRUMENT1";
            const string instrument2 = "INSTRUMENT2";
            InstrumentKey key1 = new InstrumentKey(market, instrument1);
            InstrumentKey key2 = new InstrumentKey(market, instrument2);
            Assert.IsFalse(key1.Equals(key2));
            Assert.IsFalse(key2.Equals(key1));
            Assert.IsFalse(key1.Equals(null));

            key1 = new InstrumentKey(market, instrument1);
            key2 = new InstrumentKey(market2, instrument1);
            Assert.IsFalse(key1.Equals(key2));
            Assert.IsFalse(key2.Equals(key1));
        }

        [TestMethod]
        public void GetHashCode_Test () {
            const string market = "MARKET";
            const string instrument = "INSTRUMENT";
            InstrumentKey key1 = new InstrumentKey(market, instrument);
            InstrumentKey key2 = new InstrumentKey(market, instrument);
            Assert.IsTrue(key1.GetHashCode() == key2.GetHashCode ());
            Assert.IsTrue(key1.GetHashCode() == key1.GetHashCode());
            Assert.IsTrue(key1.GetHashCode() != 0);
        }

        [TestMethod]
        public void OperatorNotEquals() {
            const string market = "MARKET";
            const string instrument = "INSTRUMENT";
            InstrumentKey key1 = new InstrumentKey(market, instrument);
            InstrumentKey key2 = new InstrumentKey(market, instrument);

            Assert.IsFalse(key1 != key1);
            Assert.IsFalse(key1 != key2);
            Assert.IsTrue(key1 != null);
        }
    }
}
